import {Directive, ElementRef, Input, OnInit} from '@angular/core';

@Directive({
  selector: '[appAutoScale]'
})
export class AutoScaleDirective implements OnInit {

  @Input('appAutoScale') parmas;
  constructor(public el: ElementRef) { }

  ngOnInit() {
      const width = this.el.nativeElement.offsetWidth;
      const height = this.el.nativeElement.offsetHeight;
      const wS = this.parmas.width / width;
      const hS = this.parmas.height / height;
      const scale = wS > hS ? hS : wS;
      this.el.nativeElement.style.transform = 'scale(' + scale + ')';
  }

}
